package com.CST.controller;


import com.CST.common.api.ResultObject;
import com.CST.entity.CostDataInfo;
import com.CST.entity.EtlDepreciation;
import com.CST.service.ICostDataService;
import com.CST.service.IEtlDepreciationService;
import com.CST.util.PageHelperTool;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @author ly
* @since 2022-01-24
*/
@Api(tags = {"成本数据"})
@RestController
@RequestMapping("/CostData")

    public class CostDataController {

    @Autowired
    private ICostDataService targetService;

    @PostMapping("/getCostData")
    @ApiOperation("获取成本数据")
    public ResultObject getCostData(@RequestBody CostDataInfo entity){
        if (entity.getYear() == null || entity.getYear().isEmpty()) {
            return ResultObject.errorReturn("凭证数据未能获取年份,请联系管理员");
        }
        if (entity.getMonth() == null || entity.getMonth().isEmpty()) {
            return ResultObject.errorReturn("凭证数据未能获取月份,请联系管理员");
        }
        List<CostDataInfo> costDataSource = targetService.getCostDataSource(entity);
        PageInfo<CostDataInfo> costDataInfoPageInfo = PageHelperTool.excutePageInfo(costDataSource, entity.getPageIndex(), entity.getPageSize());
        return ResultObject.successReturn(costDataInfoPageInfo);
    }

}

